#include <iostream>
#include <unordered_map>
using namespace std;

const int kMaxN = 1e5 + 10;

int sum[kMaxN];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int n;
    string a;

    cin >> n;
    cin >> a;
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + a[i - 1] - '0' - 1;
    }
    unordered_map<int, int> sum_map;
    long long ans = 0;
    for (int i = 0; i <= n; i++) {
      sum_map[sum[i]]++;
      ans += sum_map[sum[i]] - 1;
    }
    cout << ans << '\n';
  }
  return 0;
}